// app.js
var plugin = requirePlugin("chatbot");


App({
  onLaunch() {
    if (!wx.cloud) {
      conlose.error('请使用2.2.3或以上的基础库只用云能力')
    } else {
      wx.cloud.init({
        env: 'cloud1-2g4yda3kc0f72613',
        traceUser: true,
      })
    }
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    plugin.init({
      appid: "P5Ot9PHJDechCYqDFAW1AiK6OtG3Ja", //小程序示例账户，仅供学习和参考
      openid: "asd", //用户的openid，必填项，可通过wx.login()获取code，然后通过后台接口获取openid
      userHeader: "", // 用户头像
      userName: "", // 用户昵称
      anonymous: false, // 是否允许匿名用户评价，默认为false，设为ture时，未传递userName、userHeader两个字段时将弹出登录框
      success: () => {}, //非必填
      fail: (error) => {}, //非必填
  });
   

    // 登录
    wx.login({
      success: (res) => {
        // 通过code换取openid
        if (res.code) {
          wx.request({
            url: "",
            method: "post",
            data: {
              code: res.code,
            },
            success: (res) => {
              if (res.data && res.data.openid) {
                // 获取的openid存入storage，方便之后使用
                wx.setStorageSync("openId", res.data.openid);
              }
            },
          });
        }
      },
      fail: () => {},
      complete: () => {},
    });
    console.log(plugin, "+++");
 

  },
  dealNetworkData: function(res) {
    // console.log(res.networkType)
    this.globalData.networkType = res.networkType;
    if(res.networkType == 'none') {
        wx.showModal({
            title: "提示",
            content: "当前网略异常，请检查网略并重新刷新",
            showCancel: false,
            confirmText: "知道了",
        });
    }    
},
bindNetworkChange: function() {
    var that = this;
    wx.onNetworkStatusChange(function(res) {
        that.dealNetworkData(res);
    });
},
getNetworkType: function(cb) {
    var that = this;
    wx.getNetworkType({
    success: function(res) {
        typeof cb == "function" ? cb(that.globalData.networkType) : that.dealNetworkData(res)
    }
    });
    return that.globalData.networkType;
},
  globalData:{
    urlList:[]
  }



})